﻿Imports Models.Security
Imports System.ComponentModel.DataAnnotations

Namespace Users

    Public Class UserCompanyVO

        Private _userCompanyId As Integer
        Private _companyId As Integer
        Private _groupId As Integer
        Private _rolId As Integer
        Private _userId As Integer

        Private _company As CompanyVO
        Private _groups As New Generic.List(Of GroupVO)
        Private _rol As Security.RolVO
        Private _user As UserVO
        Private _preferences As New Generic.List(Of UserPreferenceVO)

        Private _userSolutions As New Generic.List(Of Solution.UserSolutionVO)

        Sub New()
        End Sub

        Sub New(entity As Data.BaseModel.UserCompany, Optional skipLoadLogin As Boolean = False)
            If entity IsNot Nothing Then
                userCompanyId = entity.UserCompanyId
                companyId = entity.CompanyId
                rolId = entity.RolId
                userId = entity.UserId

                If entity.Company IsNot Nothing Then
                    company = New CompanyVO(entity.Company)
                End If
                If entity.Rol IsNot Nothing Then
                    rol = New RolVO(entity.Rol)
                End If
                If Not skipLoadLogin AndAlso entity.User IsNot Nothing Then
                    user = New UserVO(entity.User, True)
                End If
                '' Agregar el listado de grupos
                If entity.Groups IsNot Nothing Then
                    For Each oItem As Data.BaseModel.Group In entity.Groups
                        groups.Add(New GroupVO(oItem))
                    Next
                End If
                If entity.UserPreferences IsNot Nothing Then
                    For Each oItem As Data.BaseModel.UserPreference In entity.UserPreferences
                        preferences.Add(New UserPreferenceVO(oItem))
                    Next
                End If
            End If
        End Sub

        Public Property userCompanyId As Integer
            Get
                Return _userCompanyId
            End Get
            Set(value As Integer)
                _userCompanyId = value
            End Set
        End Property

        Public Property companyId() As Integer
            Get
                Return _companyId
            End Get
            Set(ByVal value As Integer)
                _companyId = value
            End Set
        End Property
        Public Property company() As CompanyVO
            Get
                Return _company
            End Get
            Set(ByVal value As CompanyVO)
                _company = value
            End Set
        End Property
        Public Property groups() As Generic.List(Of GroupVO)
            Get
                Return _groups
            End Get
            Set(ByVal value As Generic.List(Of GroupVO))
                _groups = value
            End Set
        End Property
        Public Property rolId() As Integer
            Get
                Return _rolId
            End Get
            Set(ByVal value As Integer)
                _rolId = value
            End Set
        End Property
        Public Property rol() As Security.RolVO
            Get
                Return _rol
            End Get
            Set(ByVal value As Security.RolVO)
                _rol = value
            End Set
        End Property
        Public Property userId() As Integer
            Get
                Return _userId
            End Get
            Set(ByVal value As Integer)
                _userId = value
            End Set
        End Property

        Public Property user() As UserVO
            Get
                Return _user
            End Get
            Set(ByVal value As UserVO)
                _user = value
            End Set
        End Property

        Public Property preferences() As Generic.List(Of UserPreferenceVO)
            Get
                Return _preferences
            End Get
            Set(ByVal value As Generic.List(Of UserPreferenceVO))
                _preferences = value
            End Set
        End Property
    End Class

End Namespace